package cn.sdormitory.component.bindValue;

import cn.sdormitory.common.utils.ContainerUtil;
import cn.sdormitory.component.bindValue.bean.info.AnnotationInfo;
import cn.sdormitory.component.bindValue.query.AnnotationQuery;
import com.google.common.collect.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@RequiredArgsConstructor
public class AnnotationContext<T extends AnnotationInfo<?>,R> {
    private final T info;
    private final List<String> variables;
    private final Table<String,String,String> params;
    @Setter
    @Getter(AccessLevel.NONE)
    private AnnotationQuery<T,R> annotationQuery;

    public boolean isEmptyVariables() {
        return ContainerUtil.isEmpty(variables);
    }

    public boolean hasVariable() {
        return ContainerUtil.notEmpty(variables);
    }

    public R invoke(){
        return annotationQuery == null ? null : annotationQuery.query(this);
    }

    public boolean hasParamsFields(){
        return info.hasParamFields();
    }

}
